<script setup>
import { reactive, ref } from 'vue'
import { useStore } from 'vuex'

const store = useStore()
const form = ref({
  uName: '',
  uTel: '',
  uPwd: ''
})
const ruleFormRef = ref()
const rules = reactive({
  uName: [
    { required: true, message: '必须要输入用户名', trigger: 'blur' },
    { min: 6, max: 18, message: '长度在6到18位', trigger: 'blur' }
  ],
  uPwd: [
    { required: true, message: '必须要输入密码', trigger: 'blur' },
    { min: 6, max: 18, message: '长度在6到18位', trigger: 'blur' }
  ],
  uTel: [
    { required: true, message: '必须要输入手机号', trigger: 'blur' },
    {
      pattern: /^1[3-9]\d{9}$/,
      message: '手机号不正确',
      trigger: 'blur'
    }
  ]
})
const handRegisterClick = () => {
  //表单验证
  ruleFormRef.value.validate((valid, fields) => {
    if (valid) {
      store.dispatch('registerUser', form.value)
    }
  })
}
</script>

<template>
  <div class="register">
    <div class="login-form">
      <div class="form-left">
        <div>
          <h1>江西省水利管理系统</h1>
        </div>
      </div>
      <div class="form-right">
        <el-form
          :model="form"
          :rules="rules"
          ref="ruleFormRef"
          label-position="top"
          label-width="120px"
          class="demo-ruleForm"
          hide-required-asterisk
        >
          <div class="title">
            <h1>注册用户</h1>
          </div>

          <el-form-item label="用户名" prop="uName">
            <el-col :span="16">
              <el-input
                v-model="form.uName"
                autocomplete="off"
                suffix-icon="Avatar"
                size="large"
              />
            </el-col>
          </el-form-item>

          <el-form-item label="密码" prop="uPwd">
            <el-col :span="16">
              <el-input
                v-model="form.uPwd"
                type="password"
                autocomplete="off"
                suffix-icon="Lock"
                size="large"
              />
            </el-col>
          </el-form-item>

          <el-form-item label="手机号" prop="uTel">
            <el-col :span="16">
              <el-input
                v-model="form.uTel"
                autocomplete="off"
                suffix-icon="Iphone"
                size="large"
              />
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-col :span="16">
              <el-button class="btn" type="primary" @click="handRegisterClick"
                >注册</el-button
              >
            </el-col>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
:deep(.el-input .el-input__icon) {
  font-size: 22px;
}
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background: url(../../assets/img/bg.png) no-repeat;
  background-size: 1000px;
  background-position: -50px -130px;

  .login-form {
    display: flex;
    width: 1156px;
    height: 630px;
    background: #f5fafe;
    border-radius: 10px;
    .form-left {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 721px;
      height: 100%;
      color: rgba(42, 130, 228, 1);
      font-size: 24px;
    }
    .form-right {
      flex: 1;
      .title {
        margin: 140px 0 30px 0;
        color: rgba(66, 76, 116, 1);
        h1 {
          font-weight: 500;
        }
      }
      .register {
        cursor: pointer;
        color: rgba(204, 204, 204, 1);
      }
      .btn {
        width: 100%;
        height: 45px;
        font-size: 18px;
        span {
          width: 100%;
          text-align: center;
        }
      }
    }
  }
}
</style>
